package com.ruoyi.project.system.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.project.system.domain.CourseQuestionCfg;
import com.ruoyi.project.system.mapper.CourseQuestionCfgMapper;
import com.ruoyi.project.system.service.ICourseQuestionCfgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 课程练习配置Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-10-07
 */
@Service
public class CourseQuestionCfgServiceImpl implements ICourseQuestionCfgService
{
    @Autowired
    private CourseQuestionCfgMapper courseQuestionCfgMapper;

    /**
     * 查询课程练习配置
     * 
     * @param id 课程练习配置ID
     * @return 课程练习配置
     */
    @Override
    public CourseQuestionCfg selectCourseQuestionCfgById(Integer id)
    {
        return courseQuestionCfgMapper.selectCourseQuestionCfgById(id);
    }

    /**
     * 查询课程练习配置列表，章节名称去重
     *
     * @param courseQuestionCfg 课程练习配置
     * @return 课程练习配置
     */
    @Override
    public List<Map<String,Object>> selectCourseQuestionCfgDistinctList(CourseQuestionCfg courseQuestionCfg)
    {
        return courseQuestionCfgMapper.selectCourseQuestionCfgDistinctList(courseQuestionCfg);
    }

    /**
     * 查询课程练习配置列表
     * 
     * @param courseQuestionCfg 课程练习配置
     * @return 课程练习配置
     */
    @Override
    public List<Map<String,Object>> selectCourseQuestionCfgList(CourseQuestionCfg courseQuestionCfg)
    {

        //return courseQuestionCfgMapper.selectCourseQuestionCfgList(courseQuestionCfg);
        return courseQuestionCfgMapper.selectCourseQuestionCfgQuList(courseQuestionCfg);
    }

    /**
     * 新增课程练习配置
     * 
     * @param courseQuestionCfg 课程练习配置
     * @return 结果
     */
    @Override
    @Transactional
    public int insertCourseQuestionCfg(CourseQuestionCfg courseQuestionCfg)
    {
        Long[] arr = new Long[]{courseQuestionCfg.getCourseCatalogId()};
        courseQuestionCfgMapper.deleteCourseQuestionCfgByCourseCatalogId(arr);
        int i=0;
        for (Integer queId : courseQuestionCfg.getList()) {
            i++;
            courseQuestionCfg.setQuestionId(queId.longValue());
            courseQuestionCfgMapper.insertCourseQuestionCfg(courseQuestionCfg);
        }
        return i;
    }

    /**
     * 修改课程练习配置
     *
     * @param courseQuestionCfg 课程练习配置
     * @return 结果
     */
    @Override
    public int updateCourseQuestionCfg(CourseQuestionCfg courseQuestionCfg)
    {
        return courseQuestionCfgMapper.updateCourseQuestionCfg(courseQuestionCfg);
    }

    /**
     * 批量删除课程练习配置
     * 
     * @param ids 需要删除的课程练习配置ID
     * @return 结果
     */
    @Override
    public int deleteCourseQuestionCfgByIds(Integer[] ids)
    {
        return courseQuestionCfgMapper.deleteCourseQuestionCfgByIds(ids);
    }

    /**
     * 删除课程练习配置信息
     * 
     * @param id 课程练习配置ID
     * @return 结果
     */
    @Override
    public int deleteCourseQuestionCfgById(Integer id)
    {
        return courseQuestionCfgMapper.deleteCourseQuestionCfgById(id);
    }

    @Override
    public List<Map<String, Object>> selectCourseQuestionCfgListByCourseCatalogId(Long courseCatalogId)
    {
        return courseQuestionCfgMapper.selectCourseQuestionCfgListByCourseCatalogId(courseCatalogId);
    }

    @Override
    public int deleteCourseQuestionCfgByCourseCatalogId(Long[] courseCatalogIds)
    {
        return courseQuestionCfgMapper.deleteCourseQuestionCfgByCourseCatalogId(courseCatalogIds);
    }
}
